package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.operation.domain.AiPresetQuestion;
import com.yfp.operation.domain.AiPrompt;
import com.yfp.operation.domain.dto.AiModelConfigDTO;
import com.yfp.operation.domain.dto.AiModelServiceInfoDTO;
import com.yfp.operation.domain.vo.AiModelConfigVO;
import com.yfp.operation.domain.vo.AiModelServiceInfoVO;
import com.yfp.operation.service.AiModelConfigService;
import com.yfp.operation.service.AiModelServiceService;
import com.yfp.operation.service.AiPresetQuestionService;
import com.yfp.operation.service.AiPromptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ai-model")
@Tag(name = "AI模型管理")
public class AIModelController extends BaseController {

    @Resource
    private AiModelServiceService aiModelServiceService;
    @Resource
    private AiModelConfigService aiModelConfigService;
    @Resource
    private AiPromptService aiPromptService;
    @Resource
    private AiPresetQuestionService aiPresetQuestionService;


    @GetMapping("/manage/info")
    @Operation(summary = "模型管理-模型详情")
    public R<AiModelServiceInfoVO> searchModelServiceInfo() {
        AiModelServiceInfoVO aiModelServiceInfoVO = aiModelServiceService.getInfoByType("silicon-flow");
        return R.ok(aiModelServiceInfoVO);
    }

    @PostMapping("/manage")
    @Operation(summary = "模型管理-模型新增or修改")
    public R<Void> saveOrUpdateModelServiceInfo(@RequestBody AiModelServiceInfoDTO aiModelServiceInfoDTO) {
        aiModelServiceService.saveOrUpdateModelServiceInfo(aiModelServiceInfoDTO);
        return R.ok();
    }

    @GetMapping("/manage/model/list")
    @Operation(summary = "模型管理-模型详情-模型列表")
    public R<List<AiModelConfigVO>> searchModelServiceInfoList(AiModelConfigDTO aiModelConfigDTO) {
        List<AiModelConfigVO> aiModelConfigVOS = aiModelConfigService.searchModelServiceInfoList(aiModelConfigDTO);
        return R.ok(aiModelConfigVOS);
    }

    @PostMapping("/manage/model/btn/list")
    @Operation(summary = "模型管理-管理按钮-模型列表")
    public R<List<AiModelConfigVO>> searchModelServiceInfoBySiliconFlow(@RequestBody AiModelServiceInfoDTO aiModelServiceInfoDTO) {
        List<AiModelConfigVO> aiModelConfigVOS = aiModelConfigService.searchModelServiceInfoBySiliconFlow(aiModelServiceInfoDTO);
        return R.ok(aiModelConfigVOS);
    }

    @PostMapping("/manage/check")
    @Operation(summary = "模型管理-模型检查")
    public R<Void> checkModelServiceInfoBySiliconFlow(@RequestBody AiModelServiceInfoDTO aiModelServiceInfoDTO) {
        aiModelServiceService.checkModelServiceInfoBySiliconFlow(aiModelServiceInfoDTO);
        return R.ok();
    }

    @GetMapping("/config/{id}")
    @Operation(summary = "模型设置-模型详情")
    public R<AiModelConfigVO> searchConfigServiceInfo(@PathVariable Long id) {
        AiModelConfigVO aiModelConfigVO = aiModelConfigService.searchConfigServiceInfo(id);
        return R.ok(aiModelConfigVO);
    }

    @PutMapping("/config")
    @Operation(summary = "模型设置-模型修改")
    public R<Void> updateConfigServiceInfo(@RequestBody AiModelConfigDTO aiModelConfigDTO) {
        aiModelConfigService.updateConfigServiceInfo(aiModelConfigDTO);
        return R.ok();
    }

    @GetMapping("/prompt")
    @Operation(summary = "提示词设置-提示词详情")
    public R<AiPrompt> searchAiPrompt() {
        AiPrompt aiPrompt = aiPromptService.searchAiPrompt();
        return R.ok(aiPrompt);
    }

    @PutMapping("/prompt")
    @Operation(summary = "提示词设置-提示词修改")
    public R<Void> updateAiPrompt(@RequestBody AiPrompt aiPrompt) {
        aiPromptService.updateAiPrompt(aiPrompt);
        return R.ok();
    }

    @PostMapping("/prompt")
    @Operation(summary = "提示词设置-提示词新增")
    public R<Void> saveAiPrompt(@RequestBody AiPrompt aiPrompt) {
        aiPromptService.saveAiPrompt(aiPrompt);
        return R.ok();
    }

    @GetMapping("/question")
    @Operation(summary = "预设问题-问题详情")
    public R<List<AiPresetQuestion>> searchAiPresetQuestion() {
        List<AiPresetQuestion> aiPresetQuestions = aiPresetQuestionService.searchAiPresetQuestion();
        return R.ok(aiPresetQuestions);
    }

    @PostMapping("/question")
    @Operation(summary = "预设问题-问题新增")
    public R<Void> saveAiPresetQuestion(@RequestBody List<AiPresetQuestion> aiPresetQuestions) {
        aiPresetQuestionService.saveAiPresetQuestion(aiPresetQuestions);
        return R.ok();
    }
}
